package com.bwhx.eruler.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.bwhx.eruler.bean.Customer;
import com.bwhx.eruler.bean.PCustomer;
import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.Project;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.service.PCustomerService;
import com.bwhx.eruler.service.ProjectService;
import com.bwhx.eruler.util.ReadExcelUtil;

/**
 * customer指的是被扫描者
 * @author Cuilitang
 *
 */
@Deprecated
@Controller
public class PCustomerController extends BaseController {
	
	@Autowired
	PCustomerService pcustomerService;
	
	@Autowired
	ProjectService projectService;	

	private Boolean insertIntoDB(LinkedList<PCustomer> customerList) {
		return pcustomerService.insert(customerList);		
	}
	
	@ResponseBody
	//@RequestMapping(value = "/page.pcustomerList.ashx")
	 public Map<String,Object> customerList(HttpSession session,Integer page,Integer rows,PCustomer pCustomer, @RequestBody String b) {
		 log.info(b);
		 Staff staff = (Staff)session.getAttribute("staff");
		pCustomer.setStaffId(staff.getsId());
		//每页的开始记录
        int start = (page-1)*rows;
        Page p = new Page(start,rows,pCustomer);
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			List<PCustomer> list = pcustomerService.list(p);
			Integer count = pcustomerService.count(pCustomer);
			log.info(list);
			log.info(count);
			
			map.put("total",count);//total键 存放总记录数，必须的  
			map.put("rows",list);//rows键 存放每页记录 list 
			for (PCustomer customer1 : list) {
				log.info(customer1);
			}
			
		}catch(Exception e){
			log.error(getTrace(e));
			map.put("meg", "失败！");
			map.put("status", "0");
		}
		
	    return map;  
	  }
	
	
	@ResponseBody
	//@RequestMapping(value = "/pcustomerListByPcodeadPpwd.ashx")
	 public Map<String,Object> pcustomerListByPcodeadPpwd(HttpServletRequest req) {
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try{
			String pcode = (String) req.getAttribute("pcode");
			String ppwd = (String) req.getAttribute("ppwd");
			Project project = new Project();
			project.setPcode(pcode);
			project.setPpwd(ppwd);
			
			Project resultProject = projectService.findprojectByPcodeadPpwd(project);
			if(resultProject==null){
				resultMap.put("msg", "项目代号或密码输入错误！");
				resultMap.put("status", "0");
				return resultMap;
			}
			
			PCustomer pCustomer = new PCustomer();
			pCustomer.setPcode(resultProject.getPcode());
			Page p = new Page(0,0,pCustomer);
	
		
	
			List<PCustomer> list = pcustomerService.list(p);
			
			
			resultMap.put("status","1");//total键 存放总记录数，必须的  
			resultMap.put("data",list);//rows键 存放每页记录 list 
			
			
		}catch(Exception e){
			log.error(getTrace(e));
			resultMap.put("msg", "失败！");
			resultMap.put("status", "0");
		}
		
	    return resultMap;  
	  }
	
	


	
	

	
	

	
	
}
